Basic C Language MCQs
-
Which of the following is a correct comment in C?
-
a) # This is a comment
-
b) // This is a comment
-
c) <!-- This is a comment -->
-
d) <comment >This is a comment </comment >
-
Which data type is used to create a variable that should store text?
-
a) char
-
b) string
-
c) text
-
d) int
-
Which of the following is the correct syntax to declare a variable in C?
-
a) int number;
-
b) integer number;
-
c) num number;
-
d) var number;
-
Which of the following is used to print a message on the screen in C?
-
a) printf();
-
b) print();
-
c) echo();
-
d) output();
-
Which of the following is the correct way to read a string input from the user in C?
-
a) scanf("%s ", &str);
-
b) input("%s ", &str);
-
c) get("%s ", &str);
-
d) read("%s ", &str);
-
Which function is used to find the length of a string in C?
-
a) strlen()
-
b) length()
-
c) strlength()
-
d) strsize()
-
What is the index of the first element in an array in C?
-
a) 0
-
b) 1
-
c) -1
-
d) None of the above
-
Which of the following is a loop construct in C?
-
a) for
-
b) while
-
c) do-while
-
d) All of the above
-
How do you declare a constant in C?
-
a) #define PI 3.14
-
b) const float PI = 3.14;
-
c) constant PI = 3.14;
-
d) Both a and b
-
Which of the following is a relational operator in C?
-
What is the correct syntax for a for loop in C?
-
a) for(initialization; condition; increment)
-
b) for(condition; initialization; increment)
-
c) for(initialization, condition, increment)
-
d) for(initialize; condition; increment)
-
What is the output of the following code?
printf("%d ", 10 >9);
-
Which keyword is used to return a value from a function?
-
a) return
-
b) exit
-
c) end
-
d) close
-
What is the size of an int data type in C (in bytes)?
-
a) 2
-
b) 4
-
c) 8
-
d) It depends on the compiler
-
Which of the following is a correct way to declare a pointer in C?
-
a) int *ptr;
-
b) int ptr*;
-
c) int * ptr;
-
d) *int ptr;
-
Which operator is used to access the value at the address stored in a pointer variable?
-
Which function is used to allocate memory dynamically in C?
-
a) malloc()
-
b) alloc()
-
c) dynamicalloc()
-
d) memalloc()
-
What will be the output of the following code?
printf("%d ", 5/2);
-
Which of the following is the correct syntax to declare a structure in C?
-
a) struct { int a; float b; } myStruct;
-
b) structure { int a; float b; } myStruct;
-
c) struct { int a; float b; } myStruct()
-
d) structure { int a; float b; } myStruct()
-
Which of the following is a valid array declaration in C?
-
a) int arr[10];
-
b) array int arr[10];
-
c) int arr[10];
-
d) int[10] arr;
-
Which of the following function is used to open a file in C?
-
a) open()
-
b) fopen()
-
c) fileopen()
-
d) openfile()
-
What is the correct way to check for the end of a file in C?
-
a) feof(file_pointer)
-
b) endfile(file_pointer)
-
c) fileend(file_pointer)
-
d) eof(file_pointer)
-
What will be the output of the following code?
int x = 5; printf("%d ", x++);
-
Which function is used to compare two strings in C?
-
a) strcmp()
-
b) compare()
-
c) strcompare()
-
d) strcomp()
-
Which of the following is not a storage class in C?
-
a) auto
-
b) register
-
c) static
-
d) public
-
Which of the following is used to define a macro in C?
-
a) #define
-
b) define
-
c) macro
-
d) #macro
-
What will be the output of the following code?
printf("%c ", 'A '+ 1);
-
Which of the following is a valid declaration of a function in C?
-
a) int func();
-
b) function int func();
-
c) int func;
-
d) func() int;
-
What does the
continue
statement do in a loop?
-
a) Skips the current iteration and continues with the next iteration
-
b) Terminates the loop
-
c) Returns control to the start of the loop
-
d) None of the above
-
Which of the following is a valid syntax for an if statement in C?
-
a) if(condition) { statements; }
-
b) if(condition) statements;
-
c) if { condition } statements;
-
d) if(condition) { statements }
-
What will be the output of the following code?
printf("%d ", 10 % 3);
-
Which of the following is used to terminate a statement in C?
-
a) Semicolon (;)
-
b) Colon (:)
-
c) Dot (.)
-
d) Comma (,)
-
Which of the following is the correct way to initialize an array in C?
-
a) int arr[3] = {1, 2, 3};
-
b) int arr[3] = [1, 2, 3];
-
c) int arr[] = {1, 2, 3};
-
d) int arr = {1, 2, 3};
-
Which of the following is not a bitwise operator in C?
-
Which of the following is used to declare an array of pointers in C?
-
a) int *arr[10];
-
b) int arr[10];
-
c) int arr*;
-
d) int *arr;
-
What is the output of the following code?
printf("%d ", 5 &3);
-
Which header file is required for using the
malloc
function?
-
a) stdlib.h
-
b) stdio.h
-
c) malloc.h
-
d) string.h
-
What is the return type of the
malloc
function?
-
a) void*
-
b) int*
-
c) char*
-
d) float*
-
What is the purpose of the
free
function in C?
-
a) To deallocate memory previously allocated by
malloc
or
calloc
-
b) To allocate memory
-
c) To free up a file
-
d) To clear the screen
-
Which of the following functions is used to write a character to the standard output in C?
-
a) putchar()
-
b) getchar()
-
c) getch()
-
d) write()
-
Which of the following function signatures is correct for main in C?
-
a) int main(void)
-
b) int main()
-
c) void main()
-
d) All of the above
-
Which of the following is the correct way to define a symbolic constant in C?
-
a) #define PI 3.14
-
b) const PI = 3.14;
-
c) define PI 3.14
-
d) PI = 3.14;
-
Which of the following is a correct way to declare a multi-dimensional array in C?
-
a) int arr[3][4];
-
b) int arr[4][3];
-
c) int arr[3,4];
-
d) int arr[4,3];
-
Which of the following functions is used to copy a string in C?
-
a) strcpy()
-
b) strncpy()
-
c) memcpy()
-
d) strcat()
-
What is the output of the following code?
printf("%d ", sizeof(int));
-
a) 2
-
b) 4
-
c) 8
-
d) Depends on the compiler
-
Which of the following is not a valid variable name in C?
-
a) _var
-
b) var1
-
c) 1var
-
d) var_1
-
What will be the output of the following code?
printf("%d ", 1 <<2);
-
Which of the following is a preprocessor directive in C?
-
a) #include
-
b) include
-
c) #include <stdio.h >
-
d) None of the above
-
Which of the following is used to skip to the next line in a file in C?
-
What is the output of the following code?
printf("%d ", 2 == 2.0);
-
a) 1
-
b) 0
-
c) 2
-
d) None of the above